#!/usr/bin/env python

import sys

tbl = {}
for l in open(sys.argv[1]):
    fields = l.split('\t')
    tbl[l[0]] = l[1]

for l in sys.stdin:
    print tbl[l.strip()]
